<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2018/1/11
 * Time: 11:18
 */
namespace app\inter\model;
use \think\Model;
use think\Db;
class DriverMesModel extends InterBase
{
    public function getDriverMes($map=array(),$field='a.*',$flag=true,$page=1,$limit=10,$config='')
    {
        $config = $config?:$this->config;
        return $flag ? Db::connect($config)->name('driver_mes_relation a')->join('__DRIVER_MESSAGE__ b','a.mes_id=b.mes_id','LEFT')
            ->where($map)->field($field)->order('a.mes_id desc,is_read desc')->page($page,$limit)->select()
            :Db::connect($config)->name('driver_mes_relation a')->join('__DRIVER_MESSAGE__ b','a.mes_id=b.mes_id','LEFT')
                ->where($map)->field($field)->find();
    }

    public function updateDriverMesRelation($map=array(),$data)
    {
        return Db::table('inter_driver_mes_relation')->where($map)->update($data);
    }

    public function addDriverMes($data)
    {
        return Db::table('inter_driver_message')->insertGetId($data);
    }

    public function addDriverMesRelation($data)
    {
        return Db::table('inter_driver_mes_relation')->insertGetId($data);
    }
}